package org.mtmi.gestures;

import org.mtmi.tuio.Trace;

public class GestureFactory {

	private static GestureFactory instance;
	
	private GestureFactory() {}
	
	/**
	 * Return the instance of the GestureFactory.  The GestureFactory
	 * is a singleton.
	 * @return
	 * 		The single instance of the gesture factory.
	 */
	public static synchronized GestureFactory getInstance() {
		if (instance == null) {
			instance = new GestureFactory();
		} 
		return instance;
	}
	
	public IGesture getGestureFromTrace(Trace trace) {
		if (TouchDownGesture.detectFromTrace(trace)) {
			return new TouchDownGesture(trace);
		}
		if (TouchUpGesture.detectFromTrace(trace)) {
			return new TouchUpGesture(trace);
		}
		if (DblClkGesture.detectFromTrace(trace)) {
			return new DblClkGesture(trace);
		}
		if (DragGesture.detectFromTrace(trace)) {
			return new DragGesture(trace);
		}
		return null;
	}

}
